package com.web.java0328springboot.controller;

import com.web.java0328springboot.entity.PageVO;
import com.web.java0328springboot.entity.ResponseResult;
import com.web.java0328springboot.entity.Student;
import com.web.java0328springboot.service.StudentService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
public class StudentController {

    @Resource
    private StudentService studentService;
    @RequestMapping(value = "/students-page",method = RequestMethod.GET)
    public ResponseResult findStudentPage(@RequestParam(name = "current",required = false,defaultValue = "1")int current,
                                          @RequestParam(name = "pageSize",required = false,defaultValue = "10")int pageSize){
        PageVO page = studentService.getStudentPage(current, pageSize);
        return new ResponseResult(200,"OK",page);
    }

    @RequestMapping(value = "student",method = RequestMethod.POST)
    public ResponseResult addStudent(Student student){
        studentService.save(student);
        return new ResponseResult(200,"OK",null);
    }

    @RequestMapping(value = "student",method = RequestMethod.PUT)
    public ResponseResult updateStudent(Student student){
        studentService.updateById(student);
        return new ResponseResult(200,"OK",null);
    }

    @RequestMapping(value = "student/{id}",method = RequestMethod.DELETE)
    public ResponseResult deleteStudent(@PathVariable Integer id){
        studentService.removeById(id);
        return new ResponseResult(200,"OK",null);
    }
}
